<template>
  <el-dialog :visible="visible" title="排序" :close-on-click-modal="false" width="400px" @close="close">
    <el-row>
      移动到第
      <el-input-number v-model="sortValue" :min="1" :step="1" controls-position="right" />
      位
    </el-row>
    <el-row type="flex" justify="end" class="sort-action">
      <el-button size="small" @click="close">取消</el-button>
      <el-button type="primary" size="small" :disabled="disableSubmit" @click="submit">保存</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default: 1
    },
    visible: {
      type: Boolean,
      default: false
    },
    disableSubmit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      sortValue: this.value
    }
  },
  watch: {
    value: {
      handler(val) {
        this.sortValue = val
      }
    }
  },
  methods: {
    submit() {
      this.$emit('update:value', this.sortValue);
      this.$emit('submit', this.sortValue);
    },
    close() {
      this.$emit('update:visible', false);
    }
  }
}
</script>

<style>
.sort-action {
  margin-top: 18px;
}
</style>
